using Box2DSharp.Common;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;


namespace cframework.lockstep
{

    public class LockStepBehaviourEx : MonoBehaviour
    {
        public int updateOrder_fs;
        public UnityEvent update;
        public UnityEvent lateUpdate;

        public virtual void Awake()
        {
            Init();
        }

        public void Init()
        {
            if (update.GetPersistentEventCount() > 0)
            {
                LockStepWorld.current.AddUpdate(Update_LS, updateOrder_fs);
            }

            if (lateUpdate.GetPersistentEventCount() > 0)
            {
                LockStepWorld.current.AddLateUpdate(LateUpdate_LS, updateOrder_fs);
            }
        }


        protected object StartCoroutine_LS(IEnumerator e)
        {
            return LockStepWorld.current.StartCoroutine(e, this);
        }

        protected object StartTimer_LS(System.Func<bool> callback, FP delay, int repeat = -1)
        {
            return LockStepWorld.current.StartTimer(this, callback, delay, repeat);
        }


        protected void Update_LS()
        {
            update.Invoke();
        }

        protected void LateUpdate_LS()
        {
            lateUpdate.Invoke();
        }
    }




}